package com.gxa.insurance.controller;

import com.gxa.insurance.exception.BusinessException;
import com.gxa.insurance.pojo.Card;
import com.gxa.insurance.pojo.InsuranceOrder;
import com.gxa.insurance.service.CardService;
import com.gxa.insurance.service.InsuranceOrderService;
import com.gxa.insurance.util.JsonResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @date 2022/6/14
 */
@Api(value = "用户端直接预约相关的api接口")
@RestController
@RequestMapping("/insuranceOrder")
@CrossOrigin
public class InsuranceOrderController {



    @Autowired
    CardService cardService;
    @ApiOperation(value = "用户端直接预约时查询车主卡信息",produces = "query")
    @PostMapping("/selectByCardId")
    public Map selectByCardId(String carId) throws BusinessException {

        List<Card> cards = cardService.selectByCarId(carId);

        JsonResult jsonResult =new JsonResult();

        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(cards);

        return jsonResult.getMap();

    }



    @Autowired
    InsuranceOrderService insuranceOrderService;

    @ApiOperation(value = "用户端直接预约方法",produces = "query")
    @ApiImplicitParam(name ="receivePosition",value = "接车地址",paramType = "query")
    @PostMapping("/add")
    public Map add(@RequestBody InsuranceOrder insuranceOrder) throws BusinessException {

        Integer add = insuranceOrderService.add(insuranceOrder);

        JsonResult jsonResult =new JsonResult();

        jsonResult.setCode("200");
        jsonResult.setMsg("预约成功");
        jsonResult.setData(add);

        return jsonResult.getMap();

    }

}
